package com.mao.factory;

import com.mao.factory.absttact.AbstractFactory;
import com.mao.factory.absttact.Cpu;
import com.mao.factory.absttact.MainBoard;
import com.mao.factory.absttact.Power;
import com.mao.factory.absttact.huasuo.HuasuoFactory;
import com.mao.factory.absttact.huawei.HuaweiFactory;
import com.mao.factory.absttact.xiaomi.XiaomiFactory;
import com.mao.factory.method.MailSender;
import com.mao.factory.method.SenderFactory;
import com.mao.factory.method.SmsSender;
import com.mao.factory.simple.FruitFactory;
import com.mao.factory.simple.Fruits;

import java.util.concurrent.ThreadFactory;

public class Main {

    public static void main(String[] args) {
        // 简单工厂模式
//        testSimpleFactory();
        // 简单工厂方法模式
//        testFactoryMethod();
        //抽象工厂模式
        testAbsFactory();




    }

    private static void testAbsFactory() {
        AbstractFactory xiaomiFactory = new XiaomiFactory();
        AbstractFactory huaweiFactory = new HuaweiFactory();
        AbstractFactory huasuoFactory = new HuasuoFactory();

        Power power = xiaomiFactory.choosePower();
        power.createPower();
        Cpu cpu = huaweiFactory.chooseCpu();
        cpu.createCpu();
        MainBoard mainBoard = huasuoFactory.chooseMainboard();
        mainBoard.createMainBoard();
        System.out.println("电脑组装完成");


    }

    private static void testFactoryMethod() {
        SenderFactory factory = new SenderFactory();
        MailSender mailSender = factory.getMailSender();
        mailSender.send("abc@123.com","Hello World!!!");

        SmsSender smsSender = factory.getSmsSender();
        smsSender.send("13888888888","验证码ABCD");
    }

    // 简单工厂模式
    private static void testSimpleFactory() {
        Fruits apple = FruitFactory.getFruitInstance("apple");
        if (apple!=null) apple.des();
    }


}
